/*
 * Copyright [2013-2021], Alibaba Group Holding Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.calcite.rex;

import lombok.Getter;
import org.apache.calcite.rel.type.RelDataType;

/**
 * Parameter which will be evaluated in executor be for insert
 *
 * @author chenmo.cm
 */
public class RexCallParam extends RexDynamicParam {
    private final RexNode rexCall;

    private RexSequenceParam sequenceCall;

    /**
     * Mark this object wrapped a real RexDynamicParam inside,
     * so that we can compute parameter index correctly for batch insert
     * in {@link com.alibaba.polardbx.optimizer.core.rel.LogicalInsert#countParamNumInEachBatch}
     */
    @Getter
    private final boolean wrapRexDynamicParam;

    /**
     * True if this RexCallParam already computed before
     * {@link com.alibaba.polardbx.optimizer.utils.RexUtils#replaceExpressionWithLiteralParam}
     * in {@link com.alibaba.polardbx.optimizer.utils.RexUtils#updateParam}
     */
    @Getter
    private final boolean isCommonImplicitDefault;

    public RexCallParam(RelDataType type, int index, RexNode call) {
        this(type, index, call, false, false);
    }

    public RexCallParam(RelDataType type, int index, RexNode call, boolean wrapRexDynamicParam, boolean isCommonImplicitDefault) {
        super(type, index, DYNAMIC_TYPE_VALUE.REX_CALL);
        this.rexCall = call;
        this.wrapRexDynamicParam = wrapRexDynamicParam;
        this.isCommonImplicitDefault = isCommonImplicitDefault;
    }

    public RexNode getRexCall() {
        return rexCall;
    }

    public RexSequenceParam getSequenceCall() {
        return sequenceCall;
    }

    public void setSequenceCall(RexSequenceParam sequenceCall) {
        this.sequenceCall = sequenceCall;
    }

    @Override
    public boolean literal() {
        return false;
    }
}
